"""
流程：
1.打开文件，提取文件信息
2.清洗数据
3.将数据按从小到大排列，然后去除相同的，提取出最快的3个时间
"""

def get_coach_data(filename):
	"""
	数据打开，异常错误爆出
	"""
	try:
		with open(filename) as f:
			data = f.readline()
		return(data.strip().split(","))
	except IOError as e:
		print("File error" + str(e)) 


sarah=get_coach_data("sarah.txt")
james=get_coach_data("james.txt")
mikey=get_coach_data("mikey.txt")
julie=get_coach_data("julie.txt")


def sanitize(time_string):
	"""
	清洗函数
	"""
	if "-" in time_string:
		splitter = "-"
	elif ":" in time_string:
		splitter = ":"
	else:
		splitter = "."
	(mins,secs)=time_string.split(splitter)
	return mins + "." + secs
	

"""
推倒式

"""
clean_james=[sanitize(each_t) for each_t in james]
clean_julie=[sanitize(each_t) for each_t in julie]
clean_sarah=[sanitize(each_t) for each_t in sarah]
clean_mikey=[sanitize(each_t) for each_t in mikey]


print(sorted(set(clean_james))[0:3])
print(sorted(set(clean_julie))[0:3])
print(sorted(set(clean_mikey))[0:3])
print(sorted(set(clean_sarah))[0:3])



